package com.liuwei.spring.cloud.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * @author : evan.liu
 * @version V1.0
 * @Description: TODO
 * @date Date : 2022年04月26日 6:06 下午
 */
//@EnableScheduling
//@Configuration
public class GlobalScheduleConfiguration {

    /**
     * Task 默认配置类: TaskSchedulingAutoConfiguration
     * https://blog.csdn.net/bigbearxyz/article/details/121158902
     * @return 定时任务线程池
     * Singleton bean creation not allowed while singletons of this factory are in destruction
     */
    @Bean("GlobalSchedule")
    public ThreadPoolTaskScheduler threadPoolTaskScheduler(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        // 线程池大小
        threadPoolTaskScheduler.setPoolSize(10);
        // 线程名称
        threadPoolTaskScheduler.setThreadNamePrefix("TaskSchedulerPool-");
        // 等待时长
        threadPoolTaskScheduler.setAwaitTerminationSeconds(60);
        // 调度器shutdown被调用时等待当前被调度的任务完成
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
        return threadPoolTaskScheduler;
    }

    @Bean("VIPSchedule")
    public ThreadPoolTaskScheduler VIPSchedule(){
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        // 线程池大小
        threadPoolTaskScheduler.setPoolSize(10);
        // 线程名称
        threadPoolTaskScheduler.setThreadNamePrefix("TaskSchedulerPool-");
        // 等待时长
        threadPoolTaskScheduler.setAwaitTerminationSeconds(60);
        // 调度器shutdown被调用时等待当前被调度的任务完成
        threadPoolTaskScheduler.setWaitForTasksToCompleteOnShutdown(true);
        return threadPoolTaskScheduler;
    }
}
